<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
class Home extends Base
{
    //管理员首页页
    public function index()
    {
        $res = Db::name('vaccine')->select();
        $this->assign("res",$res);
        // dump($res);
        // exit;
        return $this->fetch();
    }
    //处理添加疫苗
    public function addvaccine()
    {
        $admin_id = \think\Session::get('admin_id');
        $request = Request::instance();
        $post = $request->post();
        $data = [
            'vaccine_name' =>$_POST['vaccine_name'],
            'vaccine_age' =>$_POST['vaccine_age'],
            'vaccine_effect' =>$_POST['vaccine_effect'],
            'admin_id' =>$admin_id,
            'vaccine_time' =>date('Y-m-d H:i:s'),
        ];
        // dump($data);
        // exit;
        $res = Db::name('vaccine')->insert($data);
        if($res)
        {
            return $this->success('添加成功','home/index');
        }
        else{
            return  $this->error('失败，请重新填写信息');
        }
    }
    //处理删除疫苗
    public function del($vaccine_id)
    {
        $res = Db::name('vaccine')->where('vaccine_id',$vaccine_id)->delete();
        if($res)
        {
            return $this->success('删除成功','home/index');
        }
        else{
            return  $this->error('失败，请重新填写信息');
        }
    }
}
